<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
	<head>
		<meta charset="utf-8">
	    <link href="//cdn.bootcss.com/tether/1.3.6/css/tether.min.css" rel="stylesheet">
		<link rel="stylesheet" href="css/bootstrapSwitch.css">
		<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
	</head>
	<body>
		<nav class="navbar navbar-toggleable-md navbar-inverse fixed-top bg-inverse">
	      <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
	        <span class="navbar-toggler-icon"></span>
	      </button>
	      <a class="navbar-brand" href="#">Navbar</a>
	      <div class="collapse navbar-collapse" id="navbarsExampleDefault">
	        <ul class="navbar-nav mr-auto">
	          <li class="nav-item active">
	            <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
	          </li>
	          <li class="nav-item">
	            <a class="nav-link" href="#">Link</a>
	          </li>
	          <li class="nav-item">
	            <a class="nav-link" href="proxy.html">Proxy</a>
	          </li>
	          <li class="nav-item">
	            <a class="nav-link disabled" href="#">Disabled</a>
	          </li>
	          <li class="nav-item dropdown">
	            <a class="nav-link dropdown-toggle" href="http://example.com" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dropdown</a>
	            <div class="dropdown-menu" aria-labelledby="dropdown01">
	              <a class="dropdown-item" href="#">Action</a>
	              <a class="dropdown-item" href="#">Another action</a>
	              <a class="dropdown-item" href="#">Something else here</a>
	            </div>
	          </li>
	        </ul>
	        <form class="form-inline my-2 my-lg-0">
	          <input class="form-control mr-sm-2" type="text" placeholder="Search">
	          <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
	        </form>
	      </div>
	    </nav>
		<div class="container">

      <div class="row row-offcanvas row-offcanvas-right">
        <div class="col-12 col-md-9">
          <p class="float-right hidden-md-up">
            <button type="button" class="btn btn-primary btn-sm" data-toggle="offcanvas">Toggle nav</button>
          </p>
          <div class="jumbotron">
            <h1>Hello, world!</h1>
            <p>This is an example to show the potential of an offcanvas layout pattern in Bootstrap. Try some responsive-range viewport sizes to see it in action.</p>
          </div>
          <div class="row">
            <div class="col-6 col-lg-4">
              <h2>Heading</h2>
              <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
              <p><a class="btn btn-secondary" href="#" role="button">View details »</a></p>
            </div>
            <div class="col-6 col-lg-4">
              <h2>Heading</h2>
              <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
              <p><a class="btn btn-secondary" href="#" role="button">View details »</a></p>
            </div>
          </div>
        </div>
        <div class="col-6 col-md-3 sidebar-offcanvas" id="sidebar">
          <div class="list-group">
            <a href="#" class="list-group-item active">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>
          </div>
        </div>
      </div>
      <div class="switch" data-on="success" data-off="danger" style="height: 30px">
          <input type="checkbox" checked />
      </div>
      <hr>
      
		<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
	 		添加代理地址
		</button>
	<div class="bs-example" data-example-id="striped-table">
	    <table class="table table-striped">
	      <thead>
	        <tr>
	          <th>id</th>
	          <th>原url地址</th>
	          <th>代理地址</th>
	        </tr>
	      </thead>
	      <tbody>
		    <c:forEach items="${proxys}" var="proxy">
		        <tr>
		          <th scope="row">${proxy['id']}</th>
		          <td>${proxy['resourceUrl']}</td>
		          <td>${proxy['disguiser']}</td>
		        </tr>
		    </c:forEach>
	      </tbody>
	    </table>
	  </div>
	
		<!-- Modal -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
		  <div class="modal-dialog" role="document">
				<div class="modal-content">
			      <div class="modal-header">
			        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
			        <h4 class="modal-title" id="myModalLabel">新增代理</h4>
			      </div>
			      <div class="modal-body">
					<div class="form-group has-success has-feedback">
						<label class="control-label" for="inputGroupSuccess1">代理路径:</label>
					<div class="input-group">
					  <span class="input-group-addon">http://</span>
					  <input type="text" class="form-control" id="proxySource" aria-describedby="inputGroupSuccess1Status">
					</div>
				     </div>
				     <div class="modal-footer">
				        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
				        <button type="button" class="btn btn-primary" onclick="saveProxy()">Save changes</button>
				     </div>
				  </div>
		  		</div>
			</div>
   		</div>
   		
    	<script src="https://cdn.bootcss.com/tether/1.3.6/js/tether.min.js"></script>
   		<script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
		<script src="js/bootstrapSwitch.js"></script>
		<script type="text/javascript">
			function saveProxy(){
				var url = $('#proxySource').val();
				var data = JSON.parse('{"resourceUrl":"'+url+'"}');
				$.ajax({
					 type: "POST",
					 url: 'index/addProxy.do',
					 dataType: "json",
					 data:JSON.stringify(data),
					 success: function(res){
						 window.location.reload(); 
					 },
					 error:function(res){
					 },
					 contentType: "application/json"   //如果不加这个会出现  not support utf-8
				});
			}
			
		</script>
	</body>
</html>